package br.com.nooclix.salon.ui.dto.attendance
{
	import br.com.nooclix.salon.ui.dto.customer.CustomerTO;
	import br.com.nooclix.salon.ui.screen.attendancesheet.AttendanceSheetWindow;
	import br.com.nooclix.salon.ui.util.WindowsMessage;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	
	[RemoteClass(alias="br.com.nooclix.salon.domain.attendance.AttendanceSheet")]
	[Bindable]
	public class AttendanceSheetTO
	{
		
		public var code:int;
		
		public var date:Date;
		
		public var hour:Date;
		
		public var total:Number;
		
		public var status:String;
		
		public var attendance:ArrayCollection;
		
		public var customer:CustomerTO;
		
		public function AttendanceSheetTO()
		{
			
		}

		public function addItem(item:AttendanceTO):void{
			
			if(attendance == null){
				attendance = new ArrayCollection();
			}

			if(item.product == null){
				item.total = item.quantity * item.service.value;
			}else{
				item.total = item.quantity * item.product.value;
			}
			
			attendance.addItem(item);
			
			
		}
		
		public function removeItem(item:AttendanceTO):void{
			for(var i:int =0; i<attendance.length; i++){
				if((attendance.getItemAt(i) as AttendanceTO).product == null){
					removeService(item);
					return;
				}
			for(var i2:int =0; i2<attendance.length; i2++){
				if((attendance.getItemAt(i2) as AttendanceTO).service == null){
					removeProduct(item);
					return;
				}
			}
			}
		}
		
		private function removeProduct(item:AttendanceTO):void{
			for(var i:int=0; i< attendance.length; i++){
				if((attendance.getItemAt(i) as AttendanceTO) == item){
				attendance.removeItemAt(i);	
				}
			}
				return;
		}
		private function removeService(item:AttendanceTO):void{
			for(var i:int=0; i<attendance.length; i++){
				if((attendance.getItemAt(i) as AttendanceTO) == item){
				attendance.removeItemAt(i);
				}				
			}
				return;
		}
	}
}